import { defineStore } from 'pinia'
import api from '@/api'
import { currentNodeInfo } from './currentNodeStore';
const currentInfo = currentNodeInfo()
export const nodeinfo = defineStore('nodeinfo', {
    state: () => ({
        stageList: [] as any[], // 用于存储节点信息
    }),
    actions: {
        async getNodeInfo(data: any) {
           return await new Promise((resolve, reject) => {
                api.nodeInfo.getNodeInfo(data).then(res => {
                    console.log("获取笔记信息:", res);
                    this.stageList = res.data as any;
                    console.log("节点信息:", this.stageList);
                    resolve(res.data);
                }).catch(error => {
                    console.error("获取节点信息失败:", error);
                    reject(error);
                });

            })
        },
        async insertnewNode(data: any) {
            await api.nodeInfo.insertnewNode(data).then(res => {
                console.log("新增笔记：", res);
                //新增笔记成功更新之前节点状态
                //保存前一个对象
                currentInfo.save()
                //插入成功更新树信息
            }).catch(error => {
                console.error("新增笔记失败：", error);
            });
        },
        async deleteNode(data: any) {
            await api.nodeInfo.deleteNodeById(data).then(res => {
                console.log("删除node", res);

            }).catch(Error => {
                console.error("删除笔记失败", Error);

            });
        }
    },

});
